<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Category
 *
 * @property int $id
 * @property int|null $topid 顶级栏目
 * @property int|null $pid
 * @property int|null $mod 1文章2图片3文件4视频
 * @property int|null $channelid 所属频道ID
 * @property int|null $ispart 栏目属性（0：最终列表栏目；1：频道封面；2：外部连接）
 * @property int|null $is_default 栏目列表选项（1：链接到默认页；0：链接到列表第一页；-1：使用动态页）
 * @property int|null $corank 浏览权限
 * @property string|null $defaultname 默认页的名称
 * @property string|null $cat_name
 * @property string|null $desc 描述
 * @property string|null $keywords 关键字
 * @property string|null $temparticle 内容模板
 * 
 * 内容模板
 * 
 * 内容模板
 * 
 * 内容模板
 * @property string|null $templist 列表模板
 * @property string|null $tempindex 封面模板
 * @property string|null $tpl
 * @property int|null $sort
 * @property int|null $status 1展示2隐藏
 * @property int|null $cross 栏目交（0：不交叉；1：自动获取同名栏目内容；2：手工指定交叉栏目ID）
 * @property int|null $crossid 交叉栏目ID
 * @property string|null $content 栏目内容
 * @property string|null $slug
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Category[] $children
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereCatName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereChannelid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereCorank($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereCross($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereCrossid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereDefaultname($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereDesc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereIsDefault($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereIspart($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereKeywords($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereMod($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category wherePid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereSlug($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereTemparticle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereTempindex($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereTemplist($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereTopid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereTpl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Category whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Category extends Model
{
    //
    const DISPLAY = 1;
    const HIDDEN = 2;

    public function getStatusList(){
        return [
            self::DISPLAY =>  '展示',
            self::HIDDEN    =>  '隐藏'
        ];
    }
    public function getStatusString($status){
        return ($this->getStatusList())[$status];
    }

    public function children(){
        return $this->hasMany('App\Category','pid')->with('children');
    }
    public static function getSon($pid,$bool=false){
        if($bool){
            return self::where('pid',$pid)->where('status',self::DISPLAY)->get();
        }
        return self::where('pid',$pid)->get();
    }
    //写操作
    


}
